<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
        <in label="模糊搜索" prop="searchValue" v-model="queryParams.searchValue"   clearable @input="handleQuery"></in>



        <in label="部门id" prop="deptId" v-model="deptId" placeholder="部门id" clearable @input="handleQuery"></in>


        <in label="用户id" prop="userId" v-model="userId" placeholder="用户id" clearable @input="handleQuery"></in>


        <in label="appid" prop="appid" v-model="appid" placeholder="appid" clearable @input="handleQuery"></in>


        <in label="用户id" prop="uid" v-model="uid" placeholder="用户id" clearable @input="handleQuery"></in>


        <in label="用户姓名" prop="name" v-model="name" placeholder="用户姓名" clearable @input="handleQuery"></in>


        <in label="用户电话" prop="tel" v-model="tel" placeholder="用户电话" clearable @input="handleQuery"></in>


        <in label="微信" prop="wx" v-model="wx" placeholder="微信" clearable @input="handleQuery"></in>


      <el-form-item label="入驻类型" prop="applyType">
        <el-select v-model="queryParams.applyType" placeholder="请选择入驻类型" clearable>
          <el-option
            v-for="dict in dict.type.usr_enter_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>


        <in label="公司名称" prop="company" v-model="company" placeholder="公司名称" clearable @input="handleQuery"></in>


        <in label="法人" prop="legalPerson" v-model="legalPerson" placeholder="法人" clearable @input="handleQuery"></in>


        <in label="法人电话" prop="lpTel" v-model="lpTel" placeholder="法人电话" clearable @input="handleQuery"></in>










        <in label="店铺地址" prop="address" v-model="address" placeholder="店铺地址" clearable @input="handleQuery"></in>


        <in label="店铺经度" prop="longitude" v-model="longitude" placeholder="店铺经度" clearable @input="handleQuery"></in>


        <in label="店铺纬度" prop="latitude" v-model="latitude" placeholder="店铺纬度" clearable @input="handleQuery"></in>




      <el-form-item label="审核状态" prop="isCheck">
        <el-select v-model="queryParams.isCheck" placeholder="请选择审核状态" clearable>
          <el-option
            v-for="dict in dict.type.usr_check"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>


        <in label="驳回项" prop="rejectItem" v-model="rejectItem" placeholder="驳回项" clearable @input="handleQuery"></in>


        <in label="驳回原因" prop="rejectReson" v-model="rejectReson" placeholder="驳回原因" clearable @input="handleQuery"></in>


        <in label="审核用户id" prop="checkUid" v-model="checkUid" placeholder="审核用户id" clearable @input="handleQuery"></in>


      <el-form-item label="通过时间" prop="agreeTime">
        <el-date-picker clearable
          v-model="queryParams.agreeTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择通过时间">
        </el-date-picker>
      </el-form-item>






      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['scan:apply:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['scan:apply:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['scan:apply:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['scan:apply:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="applyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" v-if="true"/>
      <el-table-column label="部门id" align="center" prop="deptId" />
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="appid" align="center" prop="appid" />
      <el-table-column label="用户id" align="center" prop="uid" />
      <el-table-column label="用户姓名" align="center" prop="name" />
      <el-table-column label="用户电话" align="center" prop="tel" />
      <el-table-column label="微信" align="center" prop="wx" />
      <el-table-column label="入驻类型" align="center" prop="applyType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.usr_enter_type" :value="scope.row.applyType"/>
        </template>
      </el-table-column>
      <el-table-column label="公司名称" align="center" prop="company" />
      <el-table-column label="法人" align="center" prop="legalPerson" />
      <el-table-column label="法人电话" align="center" prop="lpTel" />
      <el-table-column label="营业执照" align="center" prop="businessLicense" width="100">
          <template slot-scope="scope">
              <image-preview :src="scope.row.businessLicense" :width="50" :height="50"/>
          </template>
      </el-table-column>
      <el-table-column label="食品许可证" align="center" prop="foodLicense" width="100">
          <template slot-scope="scope">
              <image-preview :src="scope.row.foodLicense" :width="50" :height="50"/>
          </template>
      </el-table-column>
      <el-table-column label="餐饮许可证" align="center" prop="cateringLicense" width="100">
          <template slot-scope="scope">
              <image-preview :src="scope.row.cateringLicense" :width="50" :height="50"/>
          </template>
      </el-table-column>
      <el-table-column label="其他材料补充" align="center" prop="others" width="100">
          <template slot-scope="scope">
              <image-preview :src="scope.row.others" :width="50" :height="50"/>
          </template>
      </el-table-column>
      <el-table-column label="店铺地址" align="center" prop="address" />
      <el-table-column label="店铺经度" align="center" prop="longitude" />
      <el-table-column label="店铺纬度" align="center" prop="latitude" />
      <el-table-column label="店内环境" align="center" prop="imgs" width="100">
          <template slot-scope="scope">
              <image-preview :src="scope.row.imgs" :width="50" :height="50"/>
          </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="isCheck">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.usr_check" :value="scope.row.isCheck"/>
        </template>
      </el-table-column>
      <el-table-column label="驳回项" align="center" prop="rejectItem" />
      <el-table-column label="驳回原因" align="center" prop="rejectReson" />
      <el-table-column label="审核用户id" align="center" prop="checkUid" />
      <el-table-column label="通过时间" align="center" prop="agreeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.agreeTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['scan:apply:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['scan:apply:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改入驻申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <in label="部门id" prop="deptId" :span="12" v-model="form.deptId" placeholder="部门id" ></in>
        <in label="用户id" prop="userId" :span="12" v-model="form.userId" placeholder="用户id" ></in>
        <in label="appid" prop="appid" :span="12" v-model="form.appid" placeholder="appid" ></in>
        <in label="用户id" prop="uid" :span="12" v-model="form.uid" placeholder="用户id" ></in>
        <in label="用户姓名" prop="name" :span="12" v-model="form.name" placeholder="用户姓名" ></in>
        <in label="用户电话" prop="tel" :span="12" v-model="form.tel" placeholder="用户电话" ></in>
        <in label="微信" prop="wx" :span="12" v-model="form.wx" placeholder="微信" ></in>
        <el-form-item label="入驻类型" prop="applyType">
          <el-select v-model="form.applyType" placeholder="请选择入驻类型">
            <el-option
              v-for="dict in dict.type.usr_enter_type"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <in label="公司名称" prop="company" :span="12" v-model="form.company" placeholder="公司名称" ></in>
        <in label="法人" prop="legalPerson" :span="12" v-model="form.legalPerson" placeholder="法人" ></in>
        <in label="法人电话" prop="lpTel" :span="12" v-model="form.lpTel" placeholder="法人电话" ></in>
        <el-form-item label="营业执照">
          <image-upload v-model="form.businessLicense"/>
        </el-form-item>
        <el-form-item label="食品许可证">
          <image-upload v-model="form.foodLicense"/>
        </el-form-item>
        <el-form-item label="餐饮许可证">
          <image-upload v-model="form.cateringLicense"/>
        </el-form-item>
        <el-form-item label="其他材料补充">
          <image-upload v-model="form.others"/>
        </el-form-item>
        <in label="店铺地址" prop="address" :span="12" v-model="form.address" placeholder="店铺地址" ></in>
        <in label="店铺经度" prop="longitude" :span="12" v-model="form.longitude" placeholder="店铺经度" ></in>
        <in label="店铺纬度" prop="latitude" :span="12" v-model="form.latitude" placeholder="店铺纬度" ></in>
        <el-form-item label="店内环境">
          <image-upload v-model="form.imgs"/>
        </el-form-item>
        <el-form-item label="审核状态" prop="isCheck">
          <el-select v-model="form.isCheck" placeholder="请选择审核状态">
            <el-option
              v-for="dict in dict.type.usr_check"
              :key="dict.value"
              :label="dict.label"
:value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <in label="驳回项" prop="rejectItem" :span="12" v-model="form.rejectItem" placeholder="驳回项" ></in>
        <el-form-item label="驳回原因" prop="rejectReson">
          <el-input v-model="form.rejectReson" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <in label="审核用户id" prop="checkUid" :span="12" v-model="form.checkUid" placeholder="审核用户id" ></in>
        <el-form-item label="通过时间" prop="agreeTime">
          <el-date-picker clearable
            v-model="form.agreeTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择通过时间">
          </el-date-picker>
        </el-form-item>
        <in label="备注" prop="remark" :span="12" v-model="form.remark" placeholder="备注" ></in>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listApply, getApply, delApply, addApply, updateApply } from "@/api/scan/apply";

export default {
  name: "Apply",
  dicts: ['usr_enter_type', 'usr_check'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入驻申请表格数据
      applyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
          searchValue: undefined,
        deptId: undefined,

        userId: undefined,

        appid: undefined,

        uid: undefined,

        name: undefined,

        tel: undefined,

        wx: undefined,

        applyType: undefined,

        company: undefined,

        legalPerson: undefined,

        lpTel: undefined,

        businessLicense: undefined,

        foodLicense: undefined,

        cateringLicense: undefined,

        others: undefined,

        address: undefined,

        longitude: undefined,

        latitude: undefined,

        imgs: undefined,

        isCheck: undefined,

        rejectItem: undefined,

        rejectReson: undefined,

        checkUid: undefined,

        agreeTime: undefined,

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询入驻申请列表 */
    getList() {
      this.loading = true;
      listApply(this.queryParams).then(response => {
        this.applyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
          searchValue: undefined,
        id: undefined,
        deptId: undefined,
        userId: undefined,
        appid: undefined,
        uid: undefined,
        name: undefined,
        tel: undefined,
        wx: undefined,
        applyType: undefined,
        company: undefined,
        legalPerson: undefined,
        lpTel: undefined,
        businessLicense: undefined,
        foodLicense: undefined,
        cateringLicense: undefined,
        others: undefined,
        address: undefined,
        longitude: undefined,
        latitude: undefined,
        imgs: undefined,
        isCheck: undefined,
        rejectItem: undefined,
        rejectReson: undefined,
        checkUid: undefined,
        agreeTime: undefined,
        createTime: undefined,
        updateTime: undefined,
        delFlag: undefined,
        createBy: undefined,
        updateBy: undefined,
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加入驻申请";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getApply(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改入驻申请";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateApply(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addApply(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除入驻申请编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delApply(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('scan/apply/export', {
        ...this.queryParams
      }, `apply_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
